package tests.delete;

import static org.junit.Assert.fail;

import model.Budget;
import model.BudgetFactory;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.workplicity.util.Helper;
import org.workplicity.worklet.WorkletContext;

/*
 * 
 * Attempts to remove all budgets from the collection
 * 
 */

public class BudgetDeleteTest01
{
	Budget budget;
	BudgetFactory factory;

	@Before
	public void setUp() throws Exception
	{
	}

	@After
	public void tearDown() throws Exception
	{
	}

	@Test
	public void test()
	{
		//Create and delete 10 budgets in a row.
		factory = new BudgetFactory();

		try
		{
			for (int i = 1; i <= 10; i++)
			{
				// Create a budget
				budget = (Budget) factory.create();
				budget.setName("Test budget " + i);

				budget.setDescription("This is delete test budget " + i);

				budget.commit();

				Boolean successful = Helper.delete(budget, "Budgets", WorkletContext.getInstance());
				
				if(!successful)
				{
					fail("Deleting 10 budgets failed");
				}
			}

		}
		catch (Exception e)
		{
			fail("Deleting 10 Budgets failed with exception: " + e);
		}
	}
}
